package com.dingwei.superiordiary.adapter.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.dingwei.superiordiary.R;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.utils.ScreenUtils;
import com.luck.picture.lib.entity.LocalMedia;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 *
 *
 * @author Administrator
 */
public class FindDetailsPicAdapter extends BaseAdapter {
    private Context context;
    private List<String> list;
    private int viewwidth = 0;
    RequestOptions  options = new RequestOptions()
            .centerCrop()
            .placeholder(R.drawable.ic_default)
            .error(R.drawable.ic_default)
            .priority(Priority.HIGH)
            .diskCacheStrategy(DiskCacheStrategy.NONE);

    public FindDetailsPicAdapter(Context context, List<String> list) {
        super();
        this.context = context;
        this.list = list;
        viewwidth = (ScreenUtils.getScreenWidth(BaseActivity.context) - context
                .getResources().getDimensionPixelSize(R.dimen.dp_52)) / 3;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }

    public void setList(List<String> list) {
        this.list = list;
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int arg0, View view, ViewGroup arg2) {
        ViewHolder viewHolder = null;
        if (null == view) {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.item_img, null);
            viewHolder = new ViewHolder(view);
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) viewHolder.allLayout.getLayoutParams();
            layoutParams.width = viewwidth;
            layoutParams.height = viewwidth;
            viewHolder.allLayout.setLayoutParams(layoutParams);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }


        Glide.with(BaseActivity.context)
                .load(list.get(arg0))
                .apply(options)
                .into(viewHolder.img);


        return view;
    }


    class ViewHolder {
        @Bind(R.id.img)
        ImageView img;
        @Bind(R.id.all_layout)
        FrameLayout allLayout;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
